package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Sale;
import cn.wolfcode.crm.mapper.SaleMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.ISaleService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class SaleServiceImpl implements ISaleService {
    Long id;
    @Autowired
    private SaleMapper mapper;
    public void save(Sale sale) {
        sale.setSaledate(new Date());
        mapper.insert(sale);
        id = sale.getId();
    }

    public void update(Sale sale) {
        mapper.updateByPrimaryKey(sale);
    }

    public void delete(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    public Sale get(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public List<Sale> list() {
        return mapper.selectAll();
    }

    public void select() {

        mapper.select(id);
    }

    public List<Map<String,Object>> saleanalyze() {
        return mapper.saleanalyze();
    }

    public PageResult query(QueryObject qo) {
        //查总条数
        int total =  mapper.queryForCount(qo);
        if(total==0){
            return new PageResult();
        }
        //查分页数量
        List<Map<String,Object>> rows = mapper.queryForList(qo);
        return new PageResult(total,rows);
    }

    public PageResult queryList(QueryObject qo) {
        //查总条数
        int total =  mapper.queryCount(qo);
        if(total==0){
            return new PageResult();
        }
        //查分页数量
        List<Map<String,Object>> rows = mapper.queryList(qo);
        return new PageResult(total,rows);
    }

    public PageResult selectData(QueryObject qo) {
        //查总条数
        int total =  mapper.queryCount(qo);
        if(total==0){
            return new PageResult();
        }
        //查分页数量
        List<Map<String,Object>> rows = mapper.selectData(qo);
        return new PageResult(total,rows);
    }

}
